<template>
    <view>
        <navHome ref="home" v-if="nav_cur == 'home'"></navHome>
        <sellerList ref="seller_list" v-if="nav_cur == 'seller_list'"></sellerList>
        <sellerItemList ref="seller_item_list" v-if="nav_cur == 'seller_item_list'"></sellerItemList>
        <navCart ref="cart" v-if="nav_cur == 'cart'"></navCart>
        <navMy ref="my" v-if="nav_cur == 'my'" :params="params"></navMy>
        <view v-if="nav_cur == 'home' || nav_cur == 'my'" class="bg-white padding-tb-30 margin-top-20 text-sm">
            <view class="flex justify-center">
                <view class="text-underline" @tap="$store.commit('userNavTo', '/agreement/base/service')">服务协议</view>
                <view class="margin-lr-20">|</view>
                <view class="text-underline" @tap="$store.commit('userNavTo', '/agreement/base/privacy')">隐私政策</view>
                <template v-if="app_type == 0">
                    <view class="margin-lr-20">|</view>
                    <view class="text-underline">
                        <a class="text-333" :href="'https://zy-jdc.oss-cn-hangzhou.aliyuncs.com/apk/joa-'+version_no+'.apk'"
                            target='_blank'>
                            安卓版
                        </a>
                    </view>
                </template>
            </view>
            <view @tap="$store.commit('userWindowOpen', 'http://www.beian.gov.cn/')" class="flex justify-center margin-top-10">©2020
                中营联享 浙ICP备17059117号-1</view>
        </view>
        <foot>
            <template #content>
                <view v-for="(info, key) in nav_list" :key="key" @tap="navChange" :data-cur="key" :class="'action ' + [nav_cur == key ? 'text-nddyny' : 'text-gray']">
                    <view :class="'cuIcon-' + [nav_cur == key ? info.iconfill : info.icon]"></view>
                    <view>{{info.name}}</view>
                </view>
            </template>
        </foot>
    </view>
</template>

<script>
    import navHome from '@/pages/page/home.vue'
    import sellerList from '@/pages/seller/list.vue'
    import sellerItemList from '@/pages/seller/itemList.vue'
    import navCart from '@/pages/seller/item/cart.vue'
    import navMy from '@/pages/user/info/my.vue'
    export default {
        components: {
            navHome,
            sellerList,
            sellerItemList,
            navCart,
            navMy
        },
        data() {
            let nav_list = {
                home: {
                    name: '首页',
                    icon: 'home',
                    iconfill: 'homefill',
                },
            };
            if (this.$store.state.user.is_seller_firm == 0) {
                nav_list = Object.assign(nav_list, {
                    seller_list: {
                        name: '商家',
                        icon: 'shop',
                        iconfill: 'shopfill',
                    },
                })
            }
            nav_list = Object.assign(nav_list, {
                seller_item_list: {
                    name: this.$store.state.user.is_seller_firm == 0 ? '商品' : '批发',
                    icon: 'goods',
                    iconfill: 'goodsfill',
                },
                cart: {
                    name: '购物车',
                    icon: 'cart',
                    iconfill: 'cartfill',
                },
                my: {
                    name: '我的',
                    icon: 'my',
                    iconfill: 'myfill',
                }
            })
            return {
                params: {},
                nav_cur: 'home',
                nav_list: nav_list,
                app_type: this.$app.app_type,
                version_no: this.$app.version_no,
            }
        },
        onLoad(params) {
            this.params = params;
            this.nav_cur = params.nav || 'home';
            if (params.message && this.nav_cur == 'my') {
                this.$store.commit('userToastSuccess', params.message)
                this.navChange(null, 'my');
            }
        },
        onShow() {
            if (this.nav_cur == 'my') {
                this.shownav_curMy();
            } else if (this.nav_cur == 'cart') {
                this.$nextTick(() => {
                    if (this.$refs.cart && this.$refs.cart.pageInit) {
                        this.$refs.cart.pageInit();
                    }
                })
            }
        },
        onReachBottom() {
            if (this.nav_cur == 'seller_list' || this.nav_cur == 'seller_item_list') {
                this.$nextTick(() => {
                    this.$refs[this.nav_cur].listAdd();
                })
            }
        },
        methods: {
            backData(data) {
                this.$refs[this.nav_cur].backData(data);
            },
            navChange(e, nav_cur) {
                this.nav_cur = nav_cur || e.currentTarget.dataset.cur
                this.shownav_curMy();

                if (this.nav_cur == 'cart') {
                    this.$nextTick(() => {
                        if (this.$refs.cart && this.$refs.cart.pageInit) {
                            this.$refs.cart.pageInit();
                        }
                    })
                }
                if (this.nav_cur != 'seller_list') {
                    this.$map.allow_backData = false;
                }
            },
            shownav_curMy() {
                if (this.nav_cur != 'my') {
                    return;
                }
                this.$store.commit('userNotLoginToLoginPage');
            },
        }
    }
</script>
